package com.cskaoyan.service.impl;

import com.cskaoyan.bean.pojo.MarketCategory;
import com.cskaoyan.bean.pojo.MarketCategoryExample;
import com.cskaoyan.bean.vo.CatalogCurrentVo;
import com.cskaoyan.bean.vo.CatalogIndexVo;
import com.cskaoyan.mapper.MarketCategoryMapper;
import com.cskaoyan.service.WxCatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :LuoXuXin
 * @version : $version
 * @date :Created in 2022/4/8   21:41
 * @description:
 * @return:
 */
@Service
public class WxCatalogServiceImpl implements WxCatalogService {
    @Autowired
    MarketCategoryMapper marketCategoryMapper;


    @Override
    public CatalogIndexVo queryAllCatalog() {
        CatalogIndexVo catalogIndexVo = new CatalogIndexVo();
        //获取当前类目（第一个参数）
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        List<MarketCategory> marketCategories =
                marketCategoryMapper.selectByExample(marketCategoryExample);
        catalogIndexVo.setCurrentCategory(marketCategories.get(0));
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        //获取一级类目（第二个参数）
        MarketCategoryExample marketCategoryExample1 = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria1 = marketCategoryExample1.createCriteria();
        criteria1.andLevelEqualTo("L1");
        List<MarketCategory> marketCategories1 = marketCategoryMapper.selectByExample(marketCategoryExample1);
        catalogIndexVo.setCategoryList(marketCategories1);
        //获取二级类目（第二个参数）
        MarketCategoryExample marketCategoryExample2 = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria2 = marketCategoryExample1.createCriteria();
        criteria1.andLevelEqualTo("L2");
        List<MarketCategory> marketCategories2 = marketCategoryMapper.selectByExample(marketCategoryExample1);
        catalogIndexVo.setCurrentSubCategory(marketCategories2);
        return catalogIndexVo;
    }

    @Override
    public CatalogCurrentVo queryOneCatalog(Integer id) {
        CatalogCurrentVo catalogCurrentVo = new CatalogCurrentVo();
        //查询该一级类目
        MarketCategory marketCategory = marketCategoryMapper.selectByPrimaryKey(id);
        catalogCurrentVo.setCurrentCategory(marketCategory);
        //查询这个一级类目下的所有二级类目
        Integer pid = marketCategory.getId();
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        criteria.andPidEqualTo(pid);
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        catalogCurrentVo.setCurrentSubCategory(marketCategories);
        return catalogCurrentVo;
    }


}
